package com.example.fw;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.netbeans.jemmy.operators.JButtonOperator;
import org.netbeans.jemmy.operators.JDialogOperator;
import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.netbeans.jemmy.operators.JTreeOperator;

public class FolderHelper extends HelpersBase {

	public FolderHelper(ApplicationManager applicationManager) {
		super(applicationManager);		// lesson 6 - 80:00
	}

	public Folders getFolders() {
		List<String> list = new ArrayList<String>();
		JTreeOperator tree = new JTreeOperator(mainFrame);
		Object[] children = tree.getChildren(tree.getRoot());
		for (Object child : children) {
			list.add("" + child);
		}
		return new Folders(list);
	}

	public String createFolder(String folderName) {
		manager.getMenuHelper().pushCreateFolder();
		JDialogOperator dialog = new JDialogOperator(mainFrame);
		new JTextFieldOperator(dialog).setText(folderName);
		new JButtonOperator(dialog, "OK").push();
		return waitMessageDialog("Warning", 3000);		// lesson 6 ~69:00
	}

	public void removeFolder(int index) {
		//Folders folders = manager.getFolderHelper().getFolders();
		selectFolder(index);
		manager.getMenuHelper().pushDelete();
		JDialogOperator dialog = new JDialogOperator(mainFrame);
		new JButtonOperator(dialog, "Yes").push();
	}

	private void selectFolder(int index) {
		JTreeOperator tree = new JTreeOperator(mainFrame);
		tree.selectRow(index);
		//randomIndex = new Random().nextInt(options.size());
		//tree.getSize();
	}
	
	public int generateRandomNumberBetween(int start, int end) {
		return new Random().nextInt(end - start) + start;
	}

//		Object[] children = tree.getChildren(tree.getRoot());
//		for (Object child : children) {
//			if (someFolderToDelete.equals("" + child))	{
//				new JTreeOperator(tree, someFolderToDelete).clickOnPath();
//				return;
//			//list.add("" + child);
//			}
//		}
//	}
}